package com.etime.shycourse.controller.accountonline;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.etime.shy.common.BaseMessage;
import com.etime.shycourse.config.PageMessage;
import com.etime.shycourse.dto.AccountHistoryDto;
import com.etime.shycourse.dto.AccountMyDto;
import com.etime.shycourse.dto.AccountUserDto;
import com.etime.shycourse.pojo.Settlement;
import com.etime.shycourse.services.account.interfaces.AccountMyService;
import com.etime.shycourse.services.interfaces.AccountService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * 提成统计，我的提成数据接口
 */
@Api(tags = "后台（前台）-我的提成数据接口。包含教师，销售，机构的我的提成")
@RestController
@RequestMapping("/sys/account/my")
public class AccountMyController {
    @Autowired
    private AccountMyService accountMyService;

    /**
     * @param settlementpay 是否支付 0-未支付  1-已支付
     * @param pageNum 第几页
     * @param pageSize 每页大小
     * @return: com.etime.shycourse.dto.AccountUserDto
     * @description: 查询用户未支付的提成总额
     **/
    @ApiOperation("分页查询用户未支付的提成总额")
    @ApiImplicitParams({
            @ApiImplicitParam(name="settlementpay",value="是否支付 传递数字 0代表未支付"),
            @ApiImplicitParam(name = "pageNum",value = "第几页"),
            @ApiImplicitParam(name = "pageSize",value = "每页多少行")
    })
    @GetMapping("/sum")
    public PageMessage<AccountUserDto> selectAccountSumByPage(Integer settlementpay,String pageNum,String pageSize,@RequestHeader("token") String token){
        PageMessage<AccountUserDto> listMessage = new PageMessage<>();
        Long Num= Long.valueOf(pageNum);
        Long Size= Long.valueOf(pageSize);
        Page<AccountUserDto> accountUserDtoPage = accountMyService.selectAccountSumByPage(settlementpay, Num, Size,token);
        if(accountUserDtoPage != null){
            listMessage.setCode(1);
            listMessage.setPagedata(accountUserDtoPage);
            listMessage.setMsg("查询成功");
        }else{
            listMessage.setCode(0);
            listMessage.setMsg("没有查询到数据");
        }
        return listMessage;
    }


    /**
     * @param settlementid 结算对象id
     * @param pageNum  第几页
     * @param pageSize  每页大小
     * @return: com.etime.shycourse.config.PageMessage<com.etime.shycourse.dto.AccountMyDto>
     * @description:  查询未支付的提成明细信息
     **/
    @ApiOperation("分页查询未支付提成明细")
    @ApiImplicitParams({
            @ApiImplicitParam(name="settlementid",value="结算对象id"),
            @ApiImplicitParam(name = "pageNum",value = "第几页"),
            @ApiImplicitParam(name = "pageSize",value = "每页多少行")
    })
    @GetMapping("/detail")
    public PageMessage<AccountMyDto> selectAccountByPage(Integer settlementid,Long pageNum,Long pageSize){
        Long Num= Long.valueOf(pageNum);
        Long Size= Long.valueOf(pageSize);
        PageMessage<AccountMyDto> listMessage = new PageMessage<>();
        Page<AccountMyDto> accountMyDtoPage = accountMyService.selectAccountMyByPage(settlementid, Num, Size);
        if(accountMyDtoPage != null){
            listMessage.setCode(1);
            listMessage.setPagedata(accountMyDtoPage);
            listMessage.setMsg("查询成功");
        }else{
            listMessage.setCode(0);
            listMessage.setMsg("没有查询到数据");
        }
        return listMessage;
    }


    /**
     * @return: java.util.List<java.lang.String>
     * @description: 统计所有支付时间
     **/
    @ApiOperation("统计所有支付时间")
    @GetMapping("/paytime/{settlementuserid}")
    public List<Settlement> selectPaytime(@PathVariable("settlementuserid") Integer settlementuserid){
        return accountMyService.selectPaytime(settlementuserid);
    }

    /**
     * @param time 支付时间
     * @return: java.util.List<com.etime.shycourse.dto.AccountUserDto>
     * @description: 查询每个时间点对应的用户信息
     **/
    @ApiOperation("查询每个时间对应的用户")
    @ApiImplicitParams({
            @ApiImplicitParam(name="time",value="结算时间")
    })
    @GetMapping("/userInfo")
    public List<AccountUserDto> selectUserInfo(String time){
        return accountMyService.selectUserInfo(time);
    }

    /**
     * @param settlementid 结算对象id
     * @param time  支付时间
     * @param pageNum 第几页
     * @param pageSize 每页大小
     * @return: com.etime.shycourse.dto.AccountHistoryDto
     * @description: 查询历史提成总览
     **/
    @ApiOperation("分页查询历史提成")
    @ApiImplicitParams({
            @ApiImplicitParam(name="settlementid",value="结算对象id"),
            @ApiImplicitParam(name="time",value="结算时间"),
            @ApiImplicitParam(name = "pageNum",value = "第几页"),
            @ApiImplicitParam(name = "pageSize",value = "每页多少行")
    })
    @GetMapping("/historydate")
    public PageMessage<AccountHistoryDto> selectAccountHistory(
            Integer settlementid,String time ,Long pageNum,Long pageSize){
        PageMessage<AccountHistoryDto> listMessage = new PageMessage<>();
        Page<AccountHistoryDto> accountHistoryDtoPage =
                accountMyService.selectAccountHistory(settlementid,time,pageNum, pageSize);
        if(accountHistoryDtoPage!=null){
            listMessage.setCode(1);
            listMessage.setPagedata(accountHistoryDtoPage);
            listMessage.setMsg("查询成功");
        }else{
            listMessage.setCode(0);
            listMessage.setMsg("没有查询到数据");
        }
        return listMessage;
    }


    /**
     * @param settlementid 结算对象id
     * @param time  支付时间
     * @param pageNum  第几页
     * @param pageSize 每页大小
     * @return: com.etime.shycourse.config.PageMessage<com.etime.shycourse.dto.AccountMyDto>
     * @description: 查询历史一层明细信息
     **/
    @ApiOperation("分页查询历史提成明细")
    @ApiImplicitParams({
            @ApiImplicitParam(name="settlementid",value="结算对象id"),
            @ApiImplicitParam(name="time",value="结算时间"),
            @ApiImplicitParam(name = "pageNum",value = "第几页"),
            @ApiImplicitParam(name = "pageSize",value = "每页多少行")
    })
    @GetMapping("/historydetail")
    public PageMessage<AccountMyDto> selectHistroyDetails(
            Integer settlementid,String time ,Long pageNum,Long pageSize){
        PageMessage<AccountMyDto> listMessage = new PageMessage<>();
        Page<AccountMyDto> accountMyDtoPage = accountMyService.selectHistroyDetails(settlementid, time,pageNum, pageSize);
        if(accountMyDtoPage.getRecords().size() > 0){
            listMessage.setCode(1);
            listMessage.setPagedata(accountMyDtoPage);
            listMessage.setMsg("查询成功");
        }else{
            listMessage.setCode(0);
            listMessage.setMsg("没有查询到数据");
        }
        return listMessage;
    }


    /*
    * 机构我的提成
    * */
    @RequestMapping("/org/{id}")
    public void detail(@PathVariable("id") int id){

    }
}
